package com.allwees.bs.c.module.order.context.listener;

import com.allwees.bs.c.module.ops.service.PointActiveDefUseService;
import com.allwees.bs.c.module.order.context.event.OrderReviewedEvent;
import com.allwees.bs.c.module.order.entity.OrderReviewItemEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

@Slf4j
@Component
public class OrderReviewedListener {

    @Autowired
    private PointActiveDefUseService pointActiveDefUseService;

    @Async
    @TransactionalEventListener
    public void on(OrderReviewedEvent event) {
        OrderReviewItemEntity orderReviewItem = (OrderReviewItemEntity) event.getSource();
        log.info("reviewed order event[order review Uuid:{}]", orderReviewItem.getUuid());

        pointActiveDefUseService.orderReviewed(orderReviewItem.getUserUuid(), orderReviewItem.getPhotos(), orderReviewItem.getOrderUuid());
    }
}
